package com.chenyue.cm.base.bean;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @author origin
 */
@Data
@ApiModel(description = "分页信息")
public class PageVo<T> {

	@ApiModelProperty(required = true, notes = "数据信息", example = "[]")
	private List<T> content;

	@ApiModelProperty(required = true, notes = "页码", example = "1")
	private long pageNum;

	@ApiModelProperty(required = true, notes = "单页数据量", example = "10")
	private long pageSize;

	@ApiModelProperty(required = true, notes = "总数据量", example = "213")
	private long total;

	private String msg;

	private int code;

	public PageVo(List<T> rows, int total) {
		super();
		this.content = rows;
		this.total = total;
		this.code = 0;
		this.msg = "";
	}

	public PageVo(PageInfo<T> page) {
		this.total = page.getTotal();
		this.code = 0;
		this.msg = "";

		this.pageNum = page.getPageNum();
		this.pageSize = page.getPageSize();
		this.content = page.getList();
	}

	public PageVo() {
		super();
	}

	@Override
	public String toString() {
		return "PageVo [content=" + content + ", total=" + total + "]";
	}

}
